/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Cronograma.java
 *
 * Created on 13/06/2011, 02:07:41
 */

package Interface;
import Utilitarios.*;

import java.util.Locale;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Ramon
 */
public class Cronograma extends javax.swing.JFrame {
int DIA[]=new int[2],MES[]=new int[2],ANO[]=new int[2];
	String data=null,Sdata=null;
	int diaSemana=0;
        MaskFormatter formatoDATA;
        String[][] linha;// [linha][coluna]
        DefaultTableModel modelo;
        
    /** Creates new form Cronograma */
    public Cronograma() {


        
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        JPanel_data = new javax.swing.JPanel();
        JL_ano = new javax.swing.JLabel();
        JY_Ano = new com.toedter.calendar.JYearChooser();
        JL_Dinicio = new javax.swing.JLabel();
        JF_DiaI = new javax.swing.JFormattedTextField();
        JL_Dfim = new javax.swing.JLabel();
        JF_DiaF = new javax.swing.JFormattedTextField();
        JPanel_diaSemana = new javax.swing.JPanel();
        JC_escolha = new javax.swing.JComboBox();
        JC_escolha1 = new javax.swing.JComboBox();
        JC_escolha3 = new javax.swing.JComboBox();
        JC_escolha4 = new javax.swing.JComboBox();
        JC_escolha2 = new javax.swing.JComboBox();
        JC_escolha5 = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        JT_tabela = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        JB_limpar = new javax.swing.JButton();
        JB_montar = new javax.swing.JButton();
        JB_salvar = new javax.swing.JButton();
        JPanel_calendario = new javax.swing.JPanel();
        JDCalendario_marc = new com.toedter.calendar.JDayChooser();
        JDCalendario_Jan = new com.toedter.calendar.JDayChooser();
        JDCalendario_fev = new com.toedter.calendar.JDayChooser();
        JDCalendario_abr = new com.toedter.calendar.JDayChooser();
        JDCalendario_maio = new com.toedter.calendar.JDayChooser();
        JDCalendario_jun = new com.toedter.calendar.JDayChooser();
        JDCalendario_jul = new com.toedter.calendar.JDayChooser();
        JDCalendario_ago = new com.toedter.calendar.JDayChooser();
        JDCalendario_set = new com.toedter.calendar.JDayChooser();
        JDCalendario_out = new com.toedter.calendar.JDayChooser();
        JDCalendario_nov = new com.toedter.calendar.JDayChooser();
        JDCalendario_dez = new com.toedter.calendar.JDayChooser();
        JL_Jan = new javax.swing.JLabel();
        JL_fev = new javax.swing.JLabel();
        JL_Marc = new javax.swing.JLabel();
        JL_ABR = new javax.swing.JLabel();
        JL_Mai = new javax.swing.JLabel();
        JL_jun = new javax.swing.JLabel();
        JL_Jul = new javax.swing.JLabel();
        JL_Ago = new javax.swing.JLabel();
        JT_set = new javax.swing.JLabel();
        JL_out = new javax.swing.JLabel();
        JL_Nov = new javax.swing.JLabel();
        JL_Dez = new javax.swing.JLabel();
        JB_atualizar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        JPanel_data.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        JL_ano.setText("Ano.:");

        JY_Ano.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JY_AnoMouseClicked(evt);
            }
        });
        JY_Ano.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                JY_AnoKeyPressed(evt);
            }
        });

        JL_Dinicio.setText("Data Início.:");

        try
        {

            formatoDATA= new MaskFormatter("##/##");

        }catch(Exception erro){

            JOptionPane.showMessageDialog(null, "Não foi possível formatar o campo ");
        }
        JF_DiaI = new JFormattedTextField(formatoDATA);

        JF_DiaI.setText(" ");

        JL_Dfim.setText("Data Fim.:");

        try
        {

            formatoDATA= new MaskFormatter("##/##");

        }catch(Exception erro){

            JOptionPane.showMessageDialog(null, "Não foi possível formatar o campo ");
        }
        JF_DiaF = new JFormattedTextField(formatoDATA);

        JF_DiaF.setText(" ");

        javax.swing.GroupLayout JPanel_dataLayout = new javax.swing.GroupLayout(JPanel_data);
        JPanel_data.setLayout(JPanel_dataLayout);
        JPanel_dataLayout.setHorizontalGroup(
            JPanel_dataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanel_dataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JPanel_dataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JL_Dinicio)
                    .addComponent(JL_Dfim)
                    .addComponent(JL_ano))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_dataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JF_DiaF, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                    .addComponent(JF_DiaI, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                    .addComponent(JY_Ano, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                .addContainerGap())
        );
        JPanel_dataLayout.setVerticalGroup(
            JPanel_dataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanel_dataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JPanel_dataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JL_ano)
                    .addComponent(JY_Ano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_dataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JL_Dinicio)
                    .addComponent(JF_DiaI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_dataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_Dfim)
                    .addComponent(JF_DiaF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        JPanel_diaSemana.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        JC_escolha.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda-feira", "Terca-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sabado", "Domingo", " " }));

        JC_escolha1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda-feira", "Terca-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sabado", "Domingo", " " }));

        JC_escolha3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda-feira", "Terca-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sabado", "Domingo", " " }));

        JC_escolha4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda-feira", "Terca-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sabado", "Domingo", " " }));

        JC_escolha2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda-feira", "Terca-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sabado", "Domingo", " " }));

        JC_escolha5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda-feira", "Terca-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sabado", "Domingo", " " }));

        javax.swing.GroupLayout JPanel_diaSemanaLayout = new javax.swing.GroupLayout(JPanel_diaSemana);
        JPanel_diaSemana.setLayout(JPanel_diaSemanaLayout);
        JPanel_diaSemanaLayout.setHorizontalGroup(
            JPanel_diaSemanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanel_diaSemanaLayout.createSequentialGroup()
                .addGroup(JPanel_diaSemanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPanel_diaSemanaLayout.createSequentialGroup()
                        .addComponent(JC_escolha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(JC_escolha3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(JPanel_diaSemanaLayout.createSequentialGroup()
                        .addComponent(JC_escolha1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(JC_escolha4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(JPanel_diaSemanaLayout.createSequentialGroup()
                        .addComponent(JC_escolha2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(JC_escolha5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        JPanel_diaSemanaLayout.setVerticalGroup(
            JPanel_diaSemanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanel_diaSemanaLayout.createSequentialGroup()
                .addGroup(JPanel_diaSemanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JC_escolha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JC_escolha3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_diaSemanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JC_escolha1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JC_escolha4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_diaSemanaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JC_escolha2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JC_escolha5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        JT_tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Data", "Conteúdo"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(JT_tabela);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        JB_limpar.setText("Limpar Tabela");
        JB_limpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_limparActionPerformed(evt);
            }
        });

        JB_montar.setText("Montar");
        JB_montar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_montarActionPerformed(evt);
            }
        });

        JB_salvar.setText("Salvar");
        JB_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_salvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JB_limpar, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                    .addComponent(JB_montar, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                    .addComponent(JB_salvar, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(JB_limpar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JB_montar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JB_salvar)
                .addGap(31, 31, 31))
        );

        JPanel_calendario.setBackground(new java.awt.Color(255, 255, 255));
        JPanel_calendario.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Calendário", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Monotype Corsiva", 3, 18), new java.awt.Color(51, 51, 51))); // NOI18N
        JPanel_calendario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JPanel_calendarioMouseClicked(evt);
            }
        });

        JDCalendario_Jan.setBackground(new java.awt.Color(255, 255, 255));
        JDCalendario_Jan.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        JL_Jan.setText("Janeiro");

        JL_fev.setText("Fevereiro");

        JL_Marc.setText("Março");

        JL_ABR.setText("Abril");

        JL_Mai.setText("Maio");

        JL_jun.setText("Junho");

        JL_Jul.setText("Julho");

        JL_Ago.setText("Agosto");

        JT_set.setText("Setembro");

        JL_out.setText("Outubro");

        JL_Nov.setText("Novembro");

        JL_Dez.setText("Dezembro");

        JB_atualizar.setText("Atualizar");
        JB_atualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JB_atualizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JPanel_calendarioLayout = new javax.swing.GroupLayout(JPanel_calendario);
        JPanel_calendario.setLayout(JPanel_calendarioLayout);
        JPanel_calendarioLayout.setHorizontalGroup(
            JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addComponent(JL_Jan)
                        .addGap(147, 147, 147)
                        .addComponent(JL_fev)
                        .addGap(136, 136, 136)
                        .addComponent(JL_Marc))
                    .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(JL_ABR)
                        .addGap(158, 158, 158)
                        .addComponent(JL_Mai)
                        .addGap(165, 165, 165)
                        .addComponent(JL_jun))
                    .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addComponent(JL_out)
                        .addGap(142, 142, 142)
                        .addComponent(JL_Nov)
                        .addGap(131, 131, 131)
                        .addComponent(JL_Dez))
                    .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                        .addGap(63, 63, 63)
                        .addComponent(JL_Jul)
                        .addGap(161, 161, 161)
                        .addComponent(JL_Ago)
                        .addGap(148, 148, 148)
                        .addComponent(JT_set))
                    .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, JPanel_calendarioLayout.createSequentialGroup()
                                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(JDCalendario_out, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(JDCalendario_jul, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(JDCalendario_ago, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                                    .addComponent(JDCalendario_nov, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, JPanel_calendarioLayout.createSequentialGroup()
                                .addComponent(JDCalendario_Jan, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(JDCalendario_fev, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE))
                            .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                                .addComponent(JDCalendario_abr, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(JDCalendario_maio, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JDCalendario_set, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .addComponent(JDCalendario_dez, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .addComponent(JDCalendario_marc, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .addComponent(JDCalendario_jun, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .addComponent(JB_atualizar))))
                .addContainerGap())
        );
        JPanel_calendarioLayout.setVerticalGroup(
            JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_fev)
                    .addComponent(JL_Jan)
                    .addComponent(JL_Marc))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JDCalendario_Jan, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JDCalendario_marc, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JDCalendario_fev, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(JL_ABR)
                        .addComponent(JL_Mai))
                    .addComponent(JL_jun))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JDCalendario_jun, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JDCalendario_abr, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JDCalendario_maio, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JL_Jul)
                    .addComponent(JL_Ago)
                    .addComponent(JT_set))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JDCalendario_jul, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JDCalendario_set, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JDCalendario_ago, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JL_out)
                    .addComponent(JL_Dez)
                    .addComponent(JL_Nov))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JPanel_calendarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JDCalendario_out, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JDCalendario_nov, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(JPanel_calendarioLayout.createSequentialGroup()
                        .addComponent(JDCalendario_dez, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JB_atualizar)))
                .addContainerGap(108, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(JPanel_data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JPanel_diaSemana, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 608, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JPanel_calendario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JPanel_calendario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                            .addComponent(JPanel_data, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(JPanel_diaSemana, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(32, 32, 32)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)))
                .addGap(32, 32, 32))
        );

        pack();
    }// </editor-fold>                        

    private void JB_montarActionPerformed(java.awt.event.ActionEvent evt) {                                          

        DataCronograma cronograma=new DataCronograma();

        
	data=JF_DiaI.getText();
	DIA[0]=Integer.parseInt(data.substring(0, 2));
	MES[0]=Integer.parseInt(data.substring(3, 5));
	ANO[0]=JY_Ano.getYear();
        //ANO[0]=Integer.parseInt(data.substring(6, 10));

        data=JF_DiaF.getText();
	DIA[1]=Integer.parseInt(data.substring(0, 2));
	MES[1]=Integer.parseInt(data.substring(3, 5));
	ANO[1]=JY_Ano.getYear();
        //ANO[1]=Integer.parseInt(data.substring(6, 10));


        data="";
        data=(String)JC_escolha.getSelectedItem();

        if(data.equals("Segunda-feira"))
		{
			diaSemana=1;
		}else
		if(data.equals("Terca-feira"))
			{
				diaSemana=2;
			}else
				if(data.equals("Quarta-feira"))
				{
					diaSemana=3;
				}else
					if(data.equals("Quinta-feira"))
					{
						diaSemana=4;
					}else
						if(data.equals("Sexta-feira"))
						{
							diaSemana=5;
						}else
						 if(data.equals("Sabado"))
						 {
							 diaSemana=6;
						 }else
							 if(data.equals("Domingo"))
							 {
								  diaSemana=0;
							 }



        if(cronograma.numDiaAno(DIA[0], MES[0], ANO[0])<cronograma.numDiaAno(DIA[1], MES[1], ANO[1]))
        {

            for(int inicio=cronograma.numDiaAno(DIA[0], MES[0], ANO[0]);inicio<=cronograma.numDiaAno(DIA[1], MES[1], ANO[1]);inicio++)
                    {
                            data="";
                            Sdata=cronograma.numDiaAno(inicio,ANO[0]);
                            if(cronograma.DiaSemana(Integer.parseInt(Sdata.substring(0, Sdata.length()-3)),Integer.parseInt( Sdata.substring(Sdata.length()-2, Sdata.length())), ANO[0])==diaSemana)
                                    {
                                    data=Sdata;
                                    preencher_tabela(data,1);


                                    }


                    }
        } else JOptionPane.showMessageDialog(null, "Ops! \nData de ínicio está maior que a data fim","Aviso",JOptionPane.WARNING_MESSAGE);

    }                                         

    private void JB_limparActionPerformed(java.awt.event.ActionEvent evt) {                                          

    LimparTabela(modelo);
    LimparTabelaConfere(modelo);
    LimparTabelaConfere(modelo);
    LimparTabelaConfere(modelo);
    

    }                                         

    private void JB_salvarActionPerformed(java.awt.event.ActionEvent evt) {                                          

        colherDadosTabela(modelo);

    }                                         

    private void JPanel_calendarioMouseClicked(java.awt.event.MouseEvent evt) {                                               

    }                                              

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  

         mostraCalendario();

    }                                 

    private void JY_AnoMouseClicked(java.awt.event.MouseEvent evt) {                                    

        
    }                                   

    private void JY_AnoKeyPressed(java.awt.event.KeyEvent evt) {                                  

        
    }                                 

    private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     

    }                                    

    private void JB_atualizarActionPerformed(java.awt.event.ActionEvent evt) {                                             

        insereCalendario();
        mostraCalendario();

    }                                            

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Cronograma().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton JB_atualizar;
    private javax.swing.JButton JB_limpar;
    private javax.swing.JButton JB_montar;
    private javax.swing.JButton JB_salvar;
    private javax.swing.JComboBox JC_escolha;
    private javax.swing.JComboBox JC_escolha1;
    private javax.swing.JComboBox JC_escolha2;
    private javax.swing.JComboBox JC_escolha3;
    private javax.swing.JComboBox JC_escolha4;
    private javax.swing.JComboBox JC_escolha5;
    private com.toedter.calendar.JDayChooser JDCalendario_Jan;
    private com.toedter.calendar.JDayChooser JDCalendario_abr;
    private com.toedter.calendar.JDayChooser JDCalendario_ago;
    private com.toedter.calendar.JDayChooser JDCalendario_dez;
    private com.toedter.calendar.JDayChooser JDCalendario_fev;
    private com.toedter.calendar.JDayChooser JDCalendario_jul;
    private com.toedter.calendar.JDayChooser JDCalendario_jun;
    private com.toedter.calendar.JDayChooser JDCalendario_maio;
    private com.toedter.calendar.JDayChooser JDCalendario_marc;
    private com.toedter.calendar.JDayChooser JDCalendario_nov;
    private com.toedter.calendar.JDayChooser JDCalendario_out;
    private com.toedter.calendar.JDayChooser JDCalendario_set;
    private javax.swing.JFormattedTextField JF_DiaF;
    private javax.swing.JFormattedTextField JF_DiaI;
    private javax.swing.JLabel JL_ABR;
    private javax.swing.JLabel JL_Ago;
    private javax.swing.JLabel JL_Dez;
    private javax.swing.JLabel JL_Dfim;
    private javax.swing.JLabel JL_Dinicio;
    private javax.swing.JLabel JL_Jan;
    private javax.swing.JLabel JL_Jul;
    private javax.swing.JLabel JL_Mai;
    private javax.swing.JLabel JL_Marc;
    private javax.swing.JLabel JL_Nov;
    private javax.swing.JLabel JL_ano;
    private javax.swing.JLabel JL_fev;
    private javax.swing.JLabel JL_jun;
    private javax.swing.JLabel JL_out;
    private javax.swing.JPanel JPanel_calendario;
    private javax.swing.JPanel JPanel_data;
    private javax.swing.JPanel JPanel_diaSemana;
    private javax.swing.JLabel JT_set;
    private javax.swing.JTable JT_tabela;
    private com.toedter.calendar.JYearChooser JY_Ano;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration                   

    public void preencher_tabela(String data, int op)
    {
        String cronograma=null;

        if(op==1){
        JT_tabela.getColumnModel().getColumn(0).setPreferredWidth(5);
        JT_tabela.getColumnModel().getColumn(1).setPreferredWidth(30);

        
        modelo=(DefaultTableModel)JT_tabela.getModel();
        modelo.addRow(new Object[]{data," "});

        

        }
        if(op==2)
        {
            JT_tabela.getColumnModel().getColumn(0).setPreferredWidth(5);
            JT_tabela.getColumnModel().getColumn(1).setPreferredWidth(30);


            // DefaultTableModel modelo=(DefaultTableModel)JT_tabela.getModel();
               modelo=(DefaultTableModel)JT_tabela.getModel();
            data="<><><><><><><><><><<><>";
            modelo.addRow(new Object[]{data,"<><><><><><><><><><><><><><><><> "});

        }

    }

   public int LimparTabela(DefaultTableModel cronograma)
   {
       for(int i=0;i<cronograma.getRowCount();i++)
       {
            cronograma.removeRow(i);
       }


       return cronograma.getColumnCount();
   }
   public int LimparTabelaConfere(DefaultTableModel cronograma)
   {
       if(cronograma.getColumnCount()>0)return LimparTabela(cronograma);
       else return 0;
   }


   public  void colherDadosTabela(DefaultTableModel cronograma)
    {

       String texto="";
       linha=new String[cronograma.getRowCount()][cronograma.getColumnCount()];
  
       for(int i=0;i<cronograma.getRowCount();i++)
       {

          linha[i][0]=(String)cronograma.getValueAt(i,0);
          linha[i][1]=(String)cronograma.getValueAt(i, 1);
           
          texto+=linha[i][0]+"  : "+linha[i][1]+"\n";
         
           
       }

    JOptionPane.showMessageDialog(null, texto);
    }
    public void mostraCalendario()
        {

                JDCalendario_Jan.setYear(JY_Ano.getYear());
                JDCalendario_fev.setYear(JY_Ano.getYear());
                JDCalendario_marc.setYear(JY_Ano.getYear());
                JDCalendario_abr.setYear(JY_Ano.getYear());
                JDCalendario_maio.setYear(JY_Ano.getYear());
                JDCalendario_jun.setYear(JY_Ano.getYear());
                JDCalendario_jul.setYear(JY_Ano.getYear());
                JDCalendario_ago.setYear(JY_Ano.getYear());
                JDCalendario_set.setYear(JY_Ano.getYear());
                JDCalendario_out.setYear(JY_Ano.getYear());
                JDCalendario_nov.setYear(JY_Ano.getYear());
                JDCalendario_dez.setYear(JY_Ano.getYear());

                JDCalendario_Jan.setEnabled(false);
                JDCalendario_fev.setEnabled(false);
                JDCalendario_marc.setEnabled(false);
                JDCalendario_abr.setEnabled(false);
                JDCalendario_maio.setEnabled(false);
                JDCalendario_jun.setEnabled(false);
                JDCalendario_jul.setEnabled(false);
                JDCalendario_ago.setEnabled(false);
                JDCalendario_set.setEnabled(false);
                JDCalendario_out.setEnabled(false);
                JDCalendario_nov.setEnabled(false);
                JDCalendario_dez.setEnabled(false);
        }

    public void insereCalendario()
    {

                JDCalendario_Jan.setMonth(0);
                JDCalendario_fev.setMonth(1);
                JDCalendario_marc.setMonth(2);
                JDCalendario_abr.setMonth(3);
                JDCalendario_maio.setMonth(4);
                JDCalendario_jun.setMonth(5);
                JDCalendario_jul.setMonth(6);
                JDCalendario_ago.setMonth(7);
                JDCalendario_set.setMonth(8);
                JDCalendario_out.setMonth(9);
                JDCalendario_nov.setMonth(10);
                JDCalendario_dez.setMonth(11);
                
                JDCalendario_Jan.setDay(1);
                JDCalendario_fev.setDay(1);
                JDCalendario_marc.setDay(1);
                JDCalendario_abr.setDay(1);
                JDCalendario_maio.setDay(1);
                JDCalendario_jun.setDay(1);
                JDCalendario_jul.setDay(1);
                JDCalendario_ago.setDay(1);
                JDCalendario_set.setDay(1);
                JDCalendario_out.setDay(1);
                JDCalendario_nov.setDay(1);
                JDCalendario_dez.setDay(1);
        }
}
